function WebToolbar(id)
{
	this.id = id;
	this.items = new Array();
	return this;
};
WebToolbar.prototype.add = function()
{
	var item={};
	if( arguments.length == 1 )
		item = arguments[0];
	else
		WebToolbarItem.apply( item, arguments );
	item.parent = this;
	this.items.push( item );
}

function WebToolbarItem(id, name, nurl,hurl,purl,durl,ser,fn,conf,enabled,statusText)
{
	this.id = id||'';
	this.name = name||'';
	this.nurl = nurl||'';
	this.hurl = hurl||'';
	this.purl = purl||'';
	this.durl = durl||'';
	this.enabled = enabled||true;
	this.fn = fn||'';
	this.serverside = ser||false;
	this.conf = conf||null;
	this.status = 0;// 0: normal, 1: hover, 2: pressed;
	this.statusText = statusText||'';
	
//	if ( this.nurl != '' )
//	{
//		this.nimg = new Image();
//		this.nimg.src = this.nurl;
//	}
//	if ( this.hurl != '' )
//	{
//		this.himg = new Image();
//		this.himg.src = this.hurl;
//	}
//	if ( this.purl != '' )
//	{
//		this.pimg = new Image();
//		this.pimg.src = this.purl;
//	}
//	if ( this.durl != '' )
//	{
//		this.dimg = new Image();
//		this.dimg.src = this.durl;
//	}
	return this;
}

WebToolbar.GetItem = function( el )
{
	while( el.className != 'wbtitem' && el.parentNode )
		el = el.parentNode;
	if ( el.className != "wbtitem" )
		return null;
	var pa = el;
	while( pa.className != "webtoolbar" && el.parentNode )
		pa = pa.parentNode;
	if( pa.className != "webtoolbar" )
		return null;
	eval( "var wbt = " + pa.id + "js;");
	for( var i=0 ; i<wbt.items.length ; i++ )
		if( wbt.items[i].name == el.name )
			return wbt.items[i];
}

WebToolbar.MouseOver = function( evt )
{
	evt = evt||window.event;
	var el = evt.target || evt.srcElement;
	var item = WebToolbar.GetItem( el );
	if( item == null )
		return;
	if ( !item.enabled )
		return;
	if ( item.hurl == '' )
		return;
	el = document.getElementById( item.id );
	el.src = item.hurl;
	item.status = 1;
	if ( typeof item.parent.setStatusFn == "function" )
		item.parent.setStatusFn( item.statusText );
}

WebToolbar.MouseOut = function( evt )
{
	evt = evt||window.event;
	var el = evt.target || evt.srcElement;
	var item = WebToolbar.GetItem( el );
	if( item == null )
		return;
	if ( !item.enabled )
		return;
	if ( item.status == 0 )
		return;
	el = document.getElementById( item.id );
	el.src = item.nurl;
	item.status = 0;
	if ( typeof item.parent.setStatusFn == "function" )
		item.parent.setStatusFn( '' );
}

WebToolbar.MouseDown = function( evt )
{
	evt = evt||window.event;
	var el = evt.target || evt.srcElement;
	if( evt.which )
	{
		if( evt.which != 1 )
			return;
	}
	else if ( evt.button != 1 )
		return;
	var item = WebToolbar.GetItem( el );
	if( item == null )
		return;
	if ( !item.enabled || item.purl == '' )
		return;
	var el = document.getElementById( item.id );
	el.src = item.purl;
	item.status = 2;
}

WebToolbar.MouseUp = function( evt )
{
	evt = evt||window.event;
	var el = evt.target || evt.srcElement;
	if( evt.which )
	{
		if( evt.which != 1 )
			return;
	}
	else if ( evt.button != 1 )
		return;
	var item = WebToolbar.GetItem( el );
	if( item == null )
		return;
	if ( !item.enabled )
		return;
	var el = document.getElementById( item.id );
	if ( item.hurl != '' )
		el.src = item.hurl;
	else
		el.src = item.nurl;
	item.status = 1;
	if ( !item.serverside )
	{
		if ( item.fn && item.fn != '' )
			eval( item.fn );
	}
	else
	{
		if ( item.conf != null && !confirm(item.conf) )
			return;
		WebToolbar.PostBack(item);
	}
}

WebToolbar.PostBack = function(item)
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf('netscape') > -1)
		theform = document.forms['aspnetForm'];
	else 
		theform = document.aspnetForm;
	if ( typeof theform == 'undefined' )
		theform = document.forms[0];
	document.getElementById(item.parent.id + '_eventArgs').value = item.name;
	if ( theform.onsubmit )
		theform.onsubmit();
	if ( item.parent.beforePoseBack != '' )
		eval(item.parent.beforePostBack);
	theform.submit();
}

